// pages/ucenter/my-funds/my-funds.js
const app = getApp();
import * as API_Shop from '../../api/shop'
import * as API_Goods from '../../api/goods'
import {
  api
} from '../../config/config.js'
import {
  Foundation,
  RegExp
} from '../../ui-utils/index.js'
import {
  md5
} from '../../lib/md5'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    arr:[],
    //分类
    oneCategoryList:'',
    choosedAreas: '',//二级分类
    SelectCa: '', //选择分类
    finished: false,//是否选择完毕
    StrOne: '', //行业分类显示
    step: 4,
    btn_1_text: '取消',
    btn_2_text: '下一步',
    step1Data: {
      company_name: '', //公司名称
      company_address: '', //公司地址
      company_phone: '', //公司电话
      company_email: '', //公司邮箱
      employee_num: '', //员工数量
      reg_money: '', //注册资金
      link_name: '', //联系人姓名
      link_phone: '', //联系人电话
    },
    step2Data: {
      legal_name: '', //法人姓名
      legal_id: '', //法人身份证号
      legal_img: '', //法人身份证电子版
      license_num: '', //营业执照编号
      license_region: '', //营业执照所在地
      license_region_text: '', //营业执照所在地
      license_add: '', //营业执照详细地址
      establish_date: '', //成立日期
      licence_start: '', //营业执照有效期开始日期
      licence_end: '', //营业执照有效期结束日期
      scope: '', //经营范围
      licence_img: '', //营业执照电子版
      organization_code: '', //组织机构代码
      code_img: '', //组织机构代码电子版
      taxes_img: '', //一般纳税人证明
    },
    step3Data: {
      bank_account_name: '', //银行开户名
      bank_number: '', //银行开户账号
      bank_name: '', //开户银行支行名称
      bank_region: '', //银行地址
      bank_img: '', //开户银行许可证电子版
      taxes_certificate_num: '', //税务登记证号
      taxes_distinguish_num: '', //纳税人识别号
      taxes_certificate_img: '' //税务登记证书
    },
    step4Data: {
      goods_management_category: '', //店铺经营类目
      shop_name: '', //店铺名称
      shop_region: '', //店铺地址
      scale_public: '', //公域让利折扣
      invite_code: '' ,//入驻邀请码
      member_name:"", //账号
      logo: '', //店铺logo
      link_phone:"",
      customItem: [],
      detailed: '请选择',
      phone:'',
      region_text:'', //所在地区
      shop_category_id: '' //行业分类
    },
    mobile: "",
    uuid: "",
    password: "",
    password2: "",
    sms_code: "",
    initTip: '发送验证码',
    endTip: '重新获取',
    sufTip: '秒后重发',
    count_time: 60,
    disabled: false,
    message: '',
    interval: null,
    rules1: [{
      name: 'company_name',
      rules: {
        required: true,
        message: '公司名称必填'
      },
    }, {
      name: 'company_address',
      rules: {
        required: true,
        message: '公司地址必填'
      },
    }, {
      name: 'company_phone',
      rules: [{
        required: true,
        message: '公司电话必填'
      }]
    }, {
      name: 'company_email',
      rules: [{
        required: true,
        message: '公司邮箱必填'
      }, {
        email: true,
        message: '邮箱格式不对'
      }],
    }, {
      name: 'employee_num',
      rules: {
        required: true,
        message: '员工总数必填'
      },
    }, {
      name: 'reg_money',
      rules: {
        required: true,
        message: '注册资金必填'
      },
    }, {
      name: 'link_name',
      rules: {
        required: true,
        message: '联系人姓名必填'
      },
    }, ],
    rules2: [{
      name: 'legal_name',
      rules: {
        required: true,
        message: '法人姓名必填'
      },
    }, {
      name: 'legal_id',
      rules: {
        required: true,
        message: '法人身份证必填'
      },
    }, {
      name: 'legal_img',
      rules: {
        required: true,
        message: '必须上传法人身份证电子版'
      },
    }, {
      name: 'license_num',
      rules: {
        required: true,
        message: '营业执照编号必填'
      },
    }, {
      name: 'license_region',
      rules: {
        required: true,
        message: '营业执照所在地必选'
      },
    }, {
      name: 'license_add',
      rules: {
        required: true,
        message: '营业执照详细地址必填'
      },
    }, {
      name: 'establish_date',
      rules: {
        required: true,
        message: '成立日期必选'
      },
    }, {
      name: 'licence_start',
      rules: {
        required: true,
        message: '营业执照有效期开始日期必选'
      },
    }, {
      name: 'licence_end',
      rules: {
        required: true,
        message: '营业执照有效期结束日期必选'
      },
    }, {
      name: 'scope',
      rules: {
        required: true,
        message: '法定经营范围必填'
      },
    }, {
      name: 'licence_img',
      rules: {
        required: true,
        message: '必须上传营业执照电子版'
      },
    }],
    rules3: [{
      name: 'bank_account_name',
      rules: {
        required: true,
        message: '银行开户名必填'
      },
    }, {
      name: 'bank_number',
      rules: {
        required: true,
        message: '公司银行账户必填'
      },
    }, {
      name: 'bank_name',
      rules: {
        required: true,
        message: '开户行银行支行名称必填'
      },
    },  {
      name: 'taxes_distinguish_num',
      rules: {
        required: true,
        message: '纳税人识别号必填'
      },
    }, {
      name: 'taxes_certificate_img',
      rules: {
        required: true,
        message: '必须上传税务登记证电子版'
      },
    }],
    rules4: [
     {
      name: 'shop_name',
      rules: {
        required: true,
        message: '店铺名称必填'
      },
    }, 
    // {
    //   name: 'shop_region_text',
    //   rules: {
    //     required: true,
    //     message: '店铺地址必选'
    //   },
    // }, 
    // {
    //   name: 'goods_management_category',
    //   rules: {
    //     required: true,
    //     message: '经营类目必选'
    //   },
    // },
    {
      name: 'scale_public',
      rules: {
        required: true,
        message: '公域让利必填'
      },
    },
    // {
    //   name: 'link_phone',
    //   rules: {
    //     required: true,
    //     message: '联系人电话必填'
    //   },
    // },
    {
      name: 'logo',
      rules: {
        required: true,
        message: '店铺logo必填'
      },
    }],
    showAddressSelector: false,
    addressStep: 2,
    checkedAll: false,
    categroys: []
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const uuid = wx.getStorageSync('uuid')
    this.setData({
      uuid: uuid,
      mobile: options.mobile
    })
    console.log("mobile", options.mobile);
    API_Shop.getApplyShopInfo().then(async res => {
      console.log('res',res)
      let step1Data = {
        company_name: res.company_name,
        company_address: res.company_address,
        company_phone: res.company_phone,
        company_email: res.company_email,
        employee_num: res.employee_num,
        reg_money: res.reg_money,
        link_name: res.link_name,
        // link_phone: res.link_phone,
      }
      let step2Data = {
        legal_name: res.legal_name, //法人姓名
        legal_id: res.legal_id, //法人身份证号
        legal_img: res.legal_img, //法人身份证电子版
        license_num: res.license_num, //营业执照编号
        license_region: res.license_town_id || res.license_county_id || res.license_city_id || res.license_province_id, //营业执照所在地
        license_region_text: res.license_province ? (res.license_province + ' ' + res.license_city + ' ' + res.license_county + ' ' + res.license_town) : '',
        license_add: res.license_add, //营业执照详细地址
        establish_date: Foundation.unixToDate(res.establish_date, 'yyyy-MM-dd'), //成立日期
        licence_start: Foundation.unixToDate(res.licence_start, 'yyyy-MM-dd'), //营业执照有效期开始日期
        licence_end: Foundation.unixToDate(res.licence_end, 'yyyy-MM-dd'), //营业执照有效期结束日期
        scope: res.scope, //经营范围
        licence_img: res.licence_img, //营业执照电子版
        organization_code: res.organization_code, //组织机构代码
        code_img: res.code_img, //组织机构代码电子版
        taxes_img: res.taxes_img, //一般纳税人证明
      }
      let step3Data = {
        bank_account_name: res.bank_account_name, //银行开户名
        bank_number: res.bank_number, //银行开户账号
        bank_name: res.bank_name, //开户银行支行名称
        bank_region: res.bank_province_id ? (res.bank_town_id || res.bank_county_id || res.bank_city_id || res.bank_province_id) : '', //银行地址
        bank_region_text: res.bank_province ? (res.bank_province + ' ' + res.bank_city + ' ' + res.bank_county + ' ' + res.bank_town) : '',
        bank_img: res.bank_img, //开户银行许可证电子版
        taxes_certificate_num: res.taxes_certificate_num, //税务登记证号
        taxes_distinguish_num: res.taxes_distinguish_num, //纳税人识别号
        taxes_certificate_img: res.taxes_certificate_img //税务登记证书
      }
      let step4Data = {
        goods_management_category: res.goods_management_category, //店铺经营类目
        shop_name: res.shop_name, //店铺名称
        shop_region: res.shop_town_id ? (res.shop_town_id || res.shop_county_id || res.shop_city_id || res.shop_province_id) : '', //店铺地址
        shop_region_text: res.shop_province ? (res.shop_province + ' ' + res.shop_city + ' ' + res.shop_county + ' ' + res.shop_town) : '',
        scale_public: res.scale_public, //公域让利折扣
        member_name:res.member_name, //账号
        link_phone:res.link_phone,
        shop_category_id:this.data.StrOne,//店铺行业分类
        log:res.logo
      }

      //获取经营类目
      let c_res = await API_Goods.getBCategory();
      console.log(c_res)
      let categroys = c_res.map(item => ({
        shop_category_id: String(item.shop_category_id),
        name: item.name
      }))

      console.log(categroys)
      // if (res.goods_management_category) {
      //   let cs = res.goods_management_category.split(',')
      //   cs.map(item => {
      //     for (let index = 0; index < categroys.length; index++) {
      //       if (categroys[index].shop_category_id == item) {
      //         categroys[index].checked = true
      //         continue
      //       }
      //     }
      //   })
      // }
      this.setData({
        step1Data,
        step2Data,
        step3Data,
        step4Data,
        step: 4,
        categroys
      })
      // this.btnText(res.step || 1)
      this.btnText(4)
    })
    this.oneCategory()
  },
  onchangeChoosedItem(){
    this.oneCategory()
  },
  //分类请求
  oneCategory(){
    this.setData({
      SelectCa: '',
      arr: '',
      finished: false
    })
    API_Shop.oneCategory(0).then(res => {
      this.setData({
        oneCategoryList: res
      })
      console.log('this',this.data.oneCategoryList);
    })
  },
  //分类下一项
  onchangeItem(item){
    if(this.data.SelectCa){
      this.onchangeItems(item)
      return
    }
    // this.setData({
    //   SelectCa: item.currentTarget.dataset.item.name
    // })
    this.setData({
      arr: []
    })
    this.data.arr.push(item.currentTarget.dataset.item)
    this.setData({
        SelectCa:this.data.arr
    })
    console.log('this.data.SelectCa',this.data.SelectCa);
    API_Shop.oneCategory(item.currentTarget.dataset.item.shop_category_id).then(res => {
      this.setData({
        oneCategoryList: res
      })
      console.log('this',this.data.choosedAreas);
    })
    // this.setData({
    //   SelectCa: this.data
    // })
    console.log('item',item.currentTarget.dataset.item.shop_category_id);
  },
  //分类最后选择
  onchangeItems(item){
    console.log('item',item);
    this.data.arr.push(item.currentTarget.dataset.item)
    console.log('arr',this.data.arr);
    this.setData({
      StrOne: '',
      SelectCa:this.data.arr
    })
    this.setData({
      finished: true,
      StrOne: this.data.SelectCa[0].name + ' ' + this.data.SelectCa[1].name
    })
    this.setData({
      ['step4Data.shop_category_id']: item.currentTarget.dataset.item.shop_category_id,
      ['step4Data.goods_management_category']:'1320,12259,12218,1316,1319,16750,737,652,670,6196,1620,15248,15901,9987,9192,9847,6728,1318,1315,17329,6233,1672,5025,6144,9855,6994,11729,14065'
    })
    console.log('this.data.StrOne',this.data.StrOne);
    
    this.selectComponent('#bottomFrameOne').hideFrame();
  },
  btnText(step) {
    let btn_1_text = ""
    let btn_2_text = ""
    switch (step) {
      case 1:
        btn_1_text = "取消"
        btn_2_text = "下一步"
        break
      case 2:
        btn_1_text = "上一步"
        btn_2_text = "下一步"
        break
      case 3:
        btn_1_text = "上一步"
        btn_2_text = "下一步"
        break
      case 4:
        btn_1_text = "上一步"
        btn_2_text = "完成"
        break
    }
    this.setData({
      btn_1_text,
      btn_2_text
    })
  },
  btn_1() {
    let {
      step
    } = this.data
    switch (step) {
      case 1:
        wx.navigateBack({
          delta: 1
        })
        break;
      case 2:
        this.setData({
          step: 1,
          btn_1_text: '取消',
          btn_2_text: '下一步'
        })
        break;
      case 3:
        this.setData({
          step: 2,
          btn_1_text: '上一步',
          btn_2_text: '下一步'
        })
        break;
      case 4:
        this.setData({
          step: 3,
          btn_1_text: '上一步',
          btn_2_text: '下一步'
        })
        break;
      default:
        wx.navigateBack({
          delta: 1
        })
        break;
    }
  },
  btn_2() {
    let {
      step
    } = this.data
    console.log(step);
    
    switch (step) {
      case 1:
        this.validateStep1Data()
        break;
      case 2:
        this.validateStep2Data()
        break;
      case 3:
        this.validateStep3Data()
        break;
      case 4:
        this.validateStep4Data()
        break;
      default:
        console.log('222')
        wx.navigateBack({
          delta: 1
        })
        break;
    }
  },
  validateStep1Data() {
    this.selectComponent('#form1').validate(async (valid, errors) => {
      console.log('valid', valid, errors)
      if (valid) {
        try {
          let res = await API_Shop.applyShopStep(1, this.data.step1Data)
          delete res.step
          this.setData({
            step1Data: res,
            step: 2,
            btn_1_text: '上一步',
            btn_2_text: '下一步'
          })

        } catch (error) {

        }
      } else {
        const firstError = Object.keys(errors)
        if (firstError.length) {
          this.setData({
            error: errors[firstError[0]].message
          })
        }
      }
    })
  },
  validateStep2Data() {
    this.selectComponent('#form2').validate(async (valid, errors) => {
      // console.log('valid', valid, errors)
      console.log(this.data.step2Data)
      if (valid) {
        try {
          let {
            step2Data
          } = this.data
          step2Data.establish_date = new Date(step2Data.establish_date).getTime() / 1000
          step2Data.licence_start = new Date(step2Data.licence_start).getTime() / 1000
          step2Data.licence_end = new Date(step2Data.licence_end).getTime() / 1000
          let res = await API_Shop.applyShopStep(2, step2Data)
          delete res.step
          res.establish_date = Foundation.unixToDate(res.establish_date, 'yyyy-MM-dd')
          res.licence_start = Foundation.unixToDate(res.licence_start, 'yyyy-MM-dd')
          res.licence_end = Foundation.unixToDate(res.licence_end, 'yyyy-MM-dd')
          res.license_region = res.license_town_id || res.license_county_id || res.license_city_id || res.license_province_id
          res.license_region_text = step2Data.license_region_text
          this.setData({
            step2Data: res,
            step: 3,
            btn_1_text: '上一步',
            btn_2_text: '下一步'
          })
        } catch (error) {

        }
      } else {
        const firstError = Object.keys(errors)
        if (firstError.length) {
          this.setData({
            error: errors[firstError[0]].message
          })
        }
      }
    })
  },
  validateStep3Data() {
    this.selectComponent('#form3').validate(async (valid, errors) => {
      console.log('valid', valid, errors)
      console.log(this.data.step3Data)
      if (valid) {
        try {
          let {
            step3Data
          } = this.data
          let res = await API_Shop.applyShopStep(3, step3Data)
          delete res.step
          res.bank_region = res.bank_town_id || res.bank_county_id || res.bank_city_id || res.bank_province_id
          res.bank_region_text = step3Data.bank_region_text
          this.setData({
            step3Data: res,
            step: 4,
            btn_1_text: '上一步',
            btn_2_text: '完成'
          })

        } catch (error) {

        }
      } else {
        const firstError = Object.keys(errors)
        if (firstError.length) {
          this.setData({
            error: errors[firstError[0]].message
          })
        }
      }
    })
  },
  validateStep4Data() {
    this.setData({
      ['step4Data.link_phone']:this.data.step4Data.phone
    })
    // if(this.data.StrOne === ''){
    //   wx.showToast({
    //     title: '行业分类必填',
    //     icon: 'none'
    //   })
    //   return
    // }
    let {
      password,
      password2
    } = this.data
    //验证密码是否正确
    if (!password) {
      wx.showToast({
        title: '请输入密码！',
        icon: 'none'
      })
      return
    }
    if (!RegExp.password.test(password)) {
      wx.showToast({
        title: '密码应为6-20位英文或数字！',
        icon: 'none'
      })
      return
    }
    if (!password2) {
      wx.showToast({
        title: '请输入重复密码！',
        icon: 'none'
      })
      return
    }
    if (password !== password2) {
      wx.showToast({
        title: '两次密码不一样',
        icon: 'none'
      })
      return
    }
    // this.setData({
    //   shop_category_id: this.data.StrOne
    // })
    // step4Data.shop_category_id = 

    this.selectComponent('#form4').validate(async (valid, errors) => {
      console.log('valid', valid, errors)
      console.log('this.data.step4Data',this.data.step4Data)
      if (valid) {
        try {
          let {
            step4Data,
          } = this.data
          console.log('step4Data',step4Data);
          step4Data.scale_public /= 100
          let res = await API_Shop.applyShopStep(4, step4Data)
          console.log(res)
          //设置密码
          await API_Shop.applyShopSetPassword({
            password: md5(password),
            sms_code: this.data.sms_code,
            uuid: this.data.uuid
          })
          delete res.step
          res.shop_region = res.shop_town_id || res.shop_county_id || res.shop_city_id || res.shop_province_id
          console.log(step4Data.shop_region_text,'aaaaaa')
          res.shop_region_text = step4Data.shop_region_text
          // res.shop_region_text = "52157"
          console.log(res)
          this.setData({
            step: 5
          })

        } catch (error) {
          console.log('蒸馏啊')
        }
      } else {
        const firstError = Object.keys(errors)
        if (firstError.length) {
          this.setData({
            error: errors[firstError[0]].message
          })
        }
      }
    })
  },
  //获取验证码
  sendValidMobileSms() {
    return new Promise((resolve, reject) => {
      const {
        mobile
      } = this.data
      console.log("mobile", mobile);
      if (!/^1[3456789]\d{9}$/.test(mobile)) {
        wx.showToast({
          title: '手机号码格式有误！',
          icon: 'none'
        })
        return false
      }
      API_Shop.applyShopSendCode({
        captcha: '0000',
        uuid: this.data.uuid
      }).then(() => {
        wx.showToast({
          title: '验证码发送成功'
        })
        this.startCountDown()
        resolve()
      }).catch(reject)
    })
  },
  // 禁用 发送验证码 
  startCountDown() {
    this.setData({
      disabled: true
    })
    this.data.interval = setInterval(() => {
      if (this.data.count_time > 1) {
        this.data.count_time--
        this.data.message = this.data.count_time + this.data.sufTip
        this.setData({
          count_time: this.data.count_time,
          message: this.data.message
        })
      } else {
        clearInterval(this.data.interval)
        this.setData({
          message: '重新发送',
          count_time: 60,
          disabled: false
        })
      }
    }, 1000)
  },
  successApply() {
    wx.navigateBack({
      delta: 1
    })
  },
  formInputChange(e) {
    console.log(this.data.step)
    const {
      field,
      step
    } = e.currentTarget.dataset
    if (step == 99) {
      this.setData({
        [`${field}`]: e.detail.value
      })
    } else {
      this.setData({
        [`step${step}Data.${field}`]: e.detail.value
      })
    }
  },
  checkboxAllChange(e) {
    let categroys = this.data.categroys
    categroys.map(item => {
      item.checked = e.detail.value[0] == 'all' ? true : false
    })
    this.setData({
      categroys
    })
  },
  checkboxChange(e) {
    let categroys = this.data.categroys
    const values = e.detail.value
    for (let i = 0, lenI = categroys.length; i < lenI; ++i) {
      categroys[i].checked = false
      for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
        if (categroys[i].shop_category_id === values[j]) {
          categroys[i].checked = true
          break
        }
      }
    }
    let cs = categroys.filter(item => {
      if (item.checked)
        return item.shop_category_id
    })
    console.log(categroys)
    this.setData({
      categroys,
      // ['step4Data.goods_management_category']: cs.map(i => i.shop_category_id).join(',')
      ['step4Data.goods_management_category']:'1320,12259,12218,1316,1319,16750,737,652,670,6196,1620,15248,15901,9987,9192,9847,6728,1318,1315,17329,6233,1672,5025,6144,9855,6994,11729,14065'
    })
  },
  //打开地址选择器
  popup() {
    this.selectComponent('#bottomFrame').showFrame();
  },
  popupOne(){
    this.oneCategory()
    this.selectComponent('#bottomFrameOne').showFrame();
  },
  closeRegionpicke() {
    this.selectComponent('#bottomFrame').hideFrame();
  },
  //地址发生改变
  addressSelectorChanged(object){
    const item = object.detail
    const obj = {
      last_id: item[item.length - 1].id,
      addrs: item.map(key => { return key.local_name }).join(' ')
    }
    this.setData({
      showAddressSelector: false,
      ['step4Data.shop_region']: obj.last_id,
      ['step4Data.shop_region_text']: obj.addrs
    })
  },
  //打开地址选择器
  // openRegionpicke(e) {
  //   console.log(e)
  //   const {
  //     step
  //   } = e.currentTarget.dataset
  //   this.setData({
  //     addressStep: step
  //   })
  //   this.selectComponent('#bottomFrame').showFrame();
  // },
  // closeRegionpicke() {
  //   this.selectComponent('#bottomFrame').hideFrame();
  // },
  // //地址发生改变
  // addressSelectorChanged(object) {
  //   const item = object.detail
  //   const obj = {
  //     last_id: item[item.length - 1].id,
  //     addrs: item.map(key => {
  //       return key.local_name
  //     }).join(' ')
  //   }
    // if (this.data.addressStep == 2) {
    //   this.setData({
    //     ['step2Data.license_region']: obj.last_id,
    //     ['step2Data.license_region_text']: obj.addrs,
    //   })
    // }
    // if (this.data.addressStep == 3) {
    //   this.setData({
    //     ['step3Data.bank_region']: obj.last_id,
    //     ['step3Data.bank_region_text']: obj.addrs,
    //   })
    // }
    // if (this.data.addressStep == 4) {
    //   this.setData({
    //     ['step4Data.shop_region']: obj.last_id,
    //     ['step4Data.shop_region_text']: obj.addrs,
    //   })
    // }
    // this.setData({
    //     ['step4Data.shop_region']: obj.last_id,
    //     ['step4Data.shop_region_text']: obj.addrs,
    // })

  //   // this.setData({
  //   //   showAddressSelector: false,
  //   //   'addressForm.region': obj.last_id,
  //   //   'addressForm.addrs': obj.addrs
  //   // })
  // },
  //日期发生编号
  bindDateChange: function (e) {
    const {
      type
    } = e.currentTarget.dataset
    console.log(e)
    //TODO 提交时需要将时间转换为毫秒数
    this.setData({
      date: e.detail.value,
      [`step2Data.${type}`]: e.detail.value
    })
  },
  uploadImg(e) {
    const {
      field,
      step
    } = e.currentTarget.dataset
    let that = this
    wx.showActionSheet({
      itemList: ['从相册中选择', '拍照'],
      itemColor: '#000',
      success(res) {
        if (!res.cancel) {
          if (res.tapIndex === 0) {
            that.chooseWxImage('album', field, step)
          } else if (res.tapIndex === 1) {
            that.chooseWxImage('camera', field, step)
          }
        }
      }
    })
  },
  chooseWxImage(type, field, step) {
    let that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: [type],
      success: function (res) {
        const tempFilePaths = res.tempFilePaths
        wx.showLoading({
          title: '上传中...'
        })
        wx.uploadFile({
          url: `${api.base}/uploaders`,
          filePath: tempFilePaths[0],
          name: 'file',
          header: {
            uuid: wx.getStorageSync('uuid')
          },
          success(response) {
            wx.hideLoading()
            const data = typeof response.data === 'string' ? JSON.parse(response.data) : response.data
            that.setData({
              [`step${step}Data.${field}`]: data.url
            })
          },
          fail() {
            wx.showToast({
              title: '上传失败',
              icon: 'none'
            })
          }
        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})